package com.levi.threadutils.task;

import com.levi.threadutils.common.IndexData;
import com.levi.threadutils.domain.User;
import com.levi.threadutils.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author shentong
 * @since 2022/1/18 8:25 PM
 */
@Component
public class DataTask {

    @Autowired
    private UserService userService;

    @PostConstruct
    @Scheduled(fixedRate = 20000)
    public void dealData() {
        Integer datacount = userService.datacount();
        List<User> users = userService.userList();
        Map<String, Object> map = new HashMap<>();
        map.put("time", IndexData.DATE_TIME_FORMATTER.format(LocalDateTime.now()));
        map.put("count", datacount);
        map.put("dataList", users);
        IndexData.dataMap = map;
        System.out.println("执行了一次定时任务～～");
        System.out.println(map.get("time"));
        System.out.println(map.get("count"));
        System.out.println(map.get("dataList"));
    }
}
